home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Aminet / dev / src / wangisrc.lha / wangi / z / SM / Config.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-11  |  13KB  |  505 lines

  1. TYPE
  2.     tCData = Record
  3.         cd_Font,
  4.         cd_SFont     : tTextAttr;
  5.         cd_FontName,
  6.         cd_SFontName : String[80];
  7.         cd_ScrTit,
  8.         cd_WinTit,
  9.         cd_WitTxt,
  10.         cd_DT        : String;
  11.         cd_Pal       : Array[0..3] of Integer;
  12.         cd_ScrT, {used to be cd_Backdrop (Boolean)}
  13.         cd_Across,
  14.         cd_Down,
  15.         cd_Quals,
  16.         cd_Wait,
  17.         cd_ModeID,
  18.         cd_ScrDepth,
  19.         cd_ScrW,
  20.         cd_ScrH,
  21.         cd_App       : LongInt;
  22.         cd_RexxCmd1,
  23.         cd_RexxCmd2,
  24.         cd_RexxCmd3  : String[180];
  25.         cd_Rexxport1,
  26.         cd_RexxPort2,
  27.         cd_RexxPort3 : String[25];
  28.         cd_Flush,
  29.         cd_Test,
  30.         cd_Rexx,
  31.         cd_Wit,
  32.         cd_NoClick,
  33.         cd_WildStar,
  34.         cd_Shanghai,
  35.         cd_PopPubScr, 
  36.         cd_DTImmed,
  37.         cd_DTRepeat,
  38.         cd_LogFile   : Boolean;
  39.     end;
  40.     
  41.     { constants for cd_ScrT }
  42. CONST
  43.     ST_RAM  = 0; (* Show RAM and Time *)
  44.     ST_BACK = 1; (* Main window is backdrop *)
  45.     ST_NONE = 2; (* 'Normal' *)
  46.     ST_DT   = 3; (* Show image in the background *)
  47.     { for applicability of qualifiers }
  48.     APP_ALL = 0;
  49.     APP_ONE = 1;
  50.  
  51. VAR
  52.     CD : tCData;
  53.     
  54. {$IFDEF PREFSEDITOR}
  55.  
  56. Procedure WriteString(VAR f : BPTR; s : String);
  57. VAR
  58.     err : LONG;
  59.     
  60. begin
  61.     S := S+#10+#0; { add EOL and null term. }
  62.     err := FPuts(f,@s[1]);
  63. End;
  64.  
  65.  
  66. Procedure WriteLong(VAR f : BPTR; n : LONG);
  67. VAR
  68.     err : LONG;
  69.     s : String[50];
  70.     
  71. begin
  72.     Str(n,s);
  73.     S := S+#10+#0; { add EOL and null term. }
  74.     err := FPuts(f,@s[1]);
  75. End;
  76.  
  77. Procedure WriteBool(VAR f : BPTR; b : Boolean);
  78. VAR
  79.     err : LONG;
  80.     S : String[5];
  81.     
  82. begin
  83.     Str(Ord(b),s);
  84.     S := S+#10+#0; { add EOL and null term. }
  85.     err := FPuts(f,@s[1]);
  86. End;
  87.  
  88. Function WriteConfigFile(FName : string) : Boolean;
  89.  
  90. VAR
  91.     OutFile : BPTR; { Just save config as ascii, no need for iff }
  92.     node    : pMyNode;
  93.     OK : Boolean;
  94.     
  95. begin
  96.     WriteConfigFile := False;
  97.     FName := FName + #0;
  98.     OutFile := Open(@FName[1], MODE_NEWFILE);
  99.     If OutFile <> NULL then begin
  100.         WriteString(OutFile, 'SM.Prefs file v1.0l ©LSK 1994.');
  101.         WriteString(OutFile, '*** WARNING DONT EDIT BY HAND, THE GURU IS WAITING -- USE SMPREFS ***');
  102.         node := pMyNode(currentlist^.lh_Head);
  103.         while pMyNode(node^.LSK_Node.ln_Succ) <> NIL do begin
  104.             WriteString(outfile, PtrToPas(@node^.LSK_Name[1]));
  105.             WriteString(outfile, node^.LSK_Cmd[0]);
  106.             WriteString(outfile, node^.LSK_Cmd[1]);
  107.             WriteString(outfile, node^.LSK_Key);
  108.             WriteString(outfile, node^.LSK_RexxCmd);
  109.             WriteString(outfile, node^.LSK_RexxPort);
  110.             WriteLong(outfile, node^.LSK_Priority);
  111.             WriteLong(outfile, node^.LSK_Stack);
  112.             WriteBool(outfile, node^.LSK_ASynch);
  113.             WriteString(outfile, node^.LSK_Output);
  114.             WriteBool(outfile, node^.LSK_NewShell);
  115.             WriteString(outfile, node^.LSK_ShellFrom);
  116.             WriteBool(outfile, node^.LSK_Quit);
  117.             WriteString(outfile, node^.LSK_ShellWin);
  118.             node := pMyNode(node^.LSK_Node.ln_Succ);
  119.         end;
  120.         WriteString(outfile,'*NODE END*');
  121.         WriteString(OutFile, '');
  122.  
  123.         WriteString(outfile, PtrToPas(CD.cd_Font.ta_Name));
  124.         WriteLong(OutFile, CD.cd_Font.ta_YSize);
  125.         WriteLong(OutFile, CD.cd_Font.ta_Style);
  126.         WriteLong(OutFile, CD.cd_Font.ta_Flags);
  127.         WriteLong(OutFile, CD.cd_ModeID);
  128.         WriteLong(OutFile, CD.cd_Across); 
  129.         WriteLong(OutFile, CD.cd_Down);
  130.         WriteString(OutFile, CD.cd_ScrTit);
  131.         WriteString(OutFile, CD.cd_WinTit);
  132.         WriteLong(OutFile, CD.cd_Pal[0]);
  133.         WriteLong(OutFile, CD.cd_Pal[1]);
  134.         WriteLong(OutFile, CD.cd_Pal[2]);
  135.         WriteLong(OutFile, CD.cd_Pal[3]);
  136.         WriteLong(OutFile, CD.cd_ScrH);
  137.         WriteLong(OutFile, CD.cd_ScrW);
  138.         WriteString(OutFile, CD.cd_RexxCmd1);
  139.         WriteString(OutFile, CD.cd_RexxPort1);
  140.         WriteString(OutFile, CD.cd_RexxCmd2);
  141.         WriteString(OutFile, CD.cd_RexxPort2);
  142.         WriteBool(Outfile, CD.cd_Wit);
  143.         WriteBool(Outfile, CD.cd_Rexx);
  144.         WriteBool(Outfile, CD.cd_NoClick);
  145.         WriteLong(Outfile, CD.cd_ScrT);
  146.         WriteBool(Outfile, CD.cd_Wildstar);
  147.         WriteBool(Outfile, CD.cd_Shanghai);
  148.         WriteBool(Outfile, CD.cd_PopPubScr);    
  149.         WriteString(Outfile, PtrToPas(CD.cd_SFont.ta_Name));
  150.         WriteLong(OutFile, CD.cd_SFont.ta_YSize);
  151.         WriteLong(OutFile, CD.cd_SFont.ta_Style);
  152.         WriteLong(OutFile, CD.cd_SFont.ta_Flags);
  153.         WriteLong(OutFile, CD.cd_Quals);
  154.         WriteLong(OutFile, CD.cd_Wait);    
  155.         if CD.cd_Flush = True then
  156.             WriteString(OutFile, 'TRUE')
  157.         else
  158.             WriteString(OutFile, 'FALSE');
  159.         if CD.cd_Test = True then
  160.             WriteString(OutFile, 'TRUE')
  161.         else
  162.             WriteString(OutFile, 'FALSE');
  163.         WriteString(OutFile, CD.cd_RexxCmd3);
  164.         WriteString(OutFile, CD.cd_RexxPort3);
  165.         WriteString(OutFile, CD.cd_DT);
  166.         WriteLong(OutFile, CD.cd_ScrDepth);
  167.         WriteBool(Outfile, CD.cd_DTImmed);
  168.         WriteBool(Outfile, CD.cd_DTRepeat);
  169.         WriteLong(OutFile, CD.cd_App);
  170.         WriteBool(Outfile, CD.cd_LogFile);
  171.         WriteString(outfile,'*DEF END*');
  172.         OK := AmigaDOS.close_(outfile);
  173.         WriteConfigFile := True;
  174.     end;
  175. end;
  176.  
  177. {$ENDIF}
  178.  
  179.  
  180. Procedure ReadString(VAR f : BPTR; VAR S : String);
  181.  
  182. VAR
  183.     buf : STRPTR;
  184.  
  185. begin
  186.     buf := FGets(f,@S,Sizeof(s));
  187.     If buf <> NIL then begin
  188.         S := PtrToPas(buf);
  189.         if S[Length(S)] = #10 then
  190.             S := Copy(S,1,Length(S)-1);
  191.     end;
  192. end;
  193.  
  194. Procedure ReadLong(VAR f : BPTR; VAR n : LONG);
  195.  
  196. VAR
  197.     s : String[50];
  198.     err : Integer;
  199.     
  200. begin
  201.     ReadString(f, s);
  202.     Val(s,n,err);
  203. end;
  204.  
  205. Procedure ReadBool(VAR f : BPTR; VAR b : Boolean);
  206.  
  207. VAR
  208.     s : String[10];
  209.     n : LONG;
  210.     err : Integer;
  211.  
  212. begin
  213.     ReadString(f, s);
  214.     Val(s,n,err);
  215.     if err = 0 then begin
  216.         if n = 1 then
  217.             b := True
  218.         else
  219.             b := False;
  220.     end else 
  221.         b := False;
  222. end;
  223.  
  224. Function ReadConfigFile(FName : string) : Boolean;
  225.  
  226. TYPE
  227.     FileV = (NONVALID, V100, V101, V102, V103, V104, V105, 
  228.              V106, V107, V108, V109, V10a, V10b, V10c, V10d, V10e, V10f,
  229.              V10g, V10h, V10i, V10j, V10k, V10l);
  230. VAR
  231.     INTextF : BPTR; { Just save config as ascii, no need for iff }
  232.     node    : pMyNode;
  233.     tmpStr  : String[190];
  234.     err     : integer;
  235.     rc, OK  : Boolean;
  236.     FileVer : FileV;
  237.     tmpbyte : byte;
  238.     ti      : LONG;
  239.     
  240. begin
  241.     rc := False; { Set default exit }
  242.     FName := FName+#0; { null term. }
  243.     INTextF := Open(@FName[1], MODE_OLDFILE);
  244.     if INTextF <> 0 then begin
  245.         ReadString(INTextF, TmpStr);
  246.         if copy(tmpstr, 1, 18) = 'SM.Prefs file v1.0' then begin
  247.             Case tmpstr[19] of
  248.                 'l' : FileVer := V10l;
  249.                 'k' : FileVer := V10k;
  250.                 'j' : FileVer := V10j;
  251.                 'i' : FileVer := V10i;
  252.                 'h' : FileVer := V10h;
  253.                 'g' : FileVer := V10g; 
  254.                 'f' : FileVer := V10f;
  255.                 'e' : FileVer := V10e;
  256.                 'd' : FileVer := V10d;
  257.                 'c' : FileVer := V10c;
  258.                 'b' : FileVer := V10b;
  259.                 'a' : FileVer := V10a;
  260.                 '9' : FileVer := V109;
  261.                 '8' : FileVer := V108;
  262.                 '7' : FileVer := V107;
  263.                 '6' : FileVer := V106;
  264.                 '5' : FileVer := V105;
  265.                 '4' : FileVer := V104;
  266.                 '3' : FileVer := V103;
  267.                 '2' : FileVer := V102;
  268.                 '1' : FileVer := V101;
  269.                 '0' : FileVer := V100;
  270.                 else FileVer := NONVALID
  271.             end;
  272.             If fileVer <> NONVALID then begin
  273.                 CurrentList := AllocRemember(@RememberKey, sizeof(tList), MEMF_CLEAR);
  274.                 if CurrentList <> NIL then begin
  275.                     newlist(currentlist);
  276.                     if FileVer >= V10a then
  277.                         ReadString(INTextF, TmpStr);
  278.                     ReadString(INTextF, TmpStr);
  279.                     While TmpStr <> '*NODE END*' do begin
  280.                         { Get node mem }
  281.                         node := AllocRemember(@RememberKey, Sizeof(tMyNode), MEMF_CLEAR OR MEMF_PUBLIC);
  282.                         If node <> NIL then begin
  283.                             node^.LSK_Name := TmpStr+#0;
  284.                             if FileVer > V101 then begin
  285.                                 ReadString(INTextF, node^.LSK_Cmd[0]);
  286.                                 ReadString(INTextF, node^.LSK_Cmd[1]);
  287.                             end else begin
  288.                                 node^.LSK_Cmd[0] := ''#0;
  289.                                 ReadString(INTextF, node^.LSK_Cmd[1]);
  290.                             end;
  291.                             if UpperStr(node^.LSK_Cmd[1]) = 'NONE' then
  292.                                 node^.LSK_Cmd[1] := 'COMMENT';
  293.                                 
  294.                             ReadString(INTextF, node^.LSK_Key);
  295.                 
  296.                             if FileVer >= V103 then begin
  297.                                 ReadString(INTextF, node^.LSK_RexxCmd);
  298.                                 ReadString(INTextF, node^.LSK_RexxPort);
  299.                             end else begin
  300.                                 node^.LSK_RexxCmd := ''; 
  301.                                 node^.LSK_RexxPort := ''; 
  302.                             end; 
  303.                             if FileVer >= V105 then begin
  304.                                 ReadLong(INTextF, node^.LSK_Priority);
  305.                                 if node^.LSK_Priority > 127 then node^.LSK_Priority := 127;
  306.                                 if node^.LSK_Priority < -128 then node^.LSK_Priority := -128;
  307.                                 ReadLong(INTextF, node^.LSK_Stack);
  308.                                 ReadBool(INTextF, node^.LSK_ASynch);
  309.                             end else begin
  310.                                 node^.LSK_Priority := 0;
  311.                                 node^.LSK_Stack := 4096;
  312.                                 node^.LSK_ASynch := False;
  313.                             end;
  314.                 
  315.                             if FileVer >= V106 then
  316.                                 ReadString(INTextF, node^.LSK_Output)
  317.                             else
  318.                                 node^.LSK_Output := 'CON:0/11/640/150/Startup-Menu Command/AUTO/CLOSE/WAIT/ALT0/11/80/50';
  319.                     
  320.  
  321.                             if FileVer >= V10c then begin
  322.                                 ReadBool(INTextF, node^.LSK_NewShell);
  323.                                 ReadString(INTextF, node^.LSK_ShellFrom);
  324.                                 ReadBool(INTextF, node^.LSK_Quit);
  325.                             end else begin
  326.                                 node^.LSK_NewShell := False;
  327.                                 node^.LSK_ShellFrom := '';
  328.                                 node^.LSK_Quit := True;
  329.                             end;
  330.                  
  331.                             If FileVer >= V10g then
  332.                                 ReadString(INTextF, node^.LSK_ShellWin)
  333.                             else
  334.                                 node^.LSK_ShellWin := '';
  335.                                       
  336.                             node^.LSK_Node.ln_Name := @node^.LSK_Name[1];
  337.                             node^.LSK_Node.ln_Type := NT_USER;
  338.                             node^.LSK_Node.ln_Pri  := 0;
  339.                             AddTail(CurrentList, pNode(node));
  340.                         end;
  341.                         ReadString(INTextF, TmpStr);
  342.                     end;
  343.         
  344.                     ReadString(INTextF, tmpstr);
  345.                     ReadString(INTextF, tmpStr);
  346.                     CD.cd_FontName := tmpstr + #0;
  347.                     CD.cd_Font.ta_Name := @CD.cd_FontName[1];
  348.                     ReadLong(INTextF, ti);
  349.                     CD.cd_Font.ta_YSize := ti;
  350.                     ReadLong(INTextF, ti);
  351.                     CD.cd_Font.ta_Style := ti;
  352.                     ReadLong(INTextF, ti);
  353.                     CD.cd_Font.ta_Flags := ti;
  354.                     ReadLong(INTextF, CD.cd_ModeID);
  355.                     ReadLong(INTextF, CD.cd_Across);
  356.                     ReadLong(INTextF, CD.cd_Down); 
  357.                     ReadString(INTextF, CD.cd_ScrTit);
  358.                     ReadString(INTextF, CD.cd_WinTit);
  359.                     ReadLong(INTextF, ti);
  360.                     CD.cd_Pal[0] := ti;
  361.                     ReadLong(INTextF, ti);
  362.                     CD.cd_Pal[1] := ti;
  363.                     ReadLong(INTextF, ti);
  364.                     CD.cd_Pal[2] := ti;
  365.                     ReadLong(INTextF, ti);
  366.                     CD.cd_Pal[3] := ti;
  367.                     if FileVer >= V102 then begin
  368.                         ReadLong(INTextF, CD.cd_ScrH);
  369.                         ReadLong(INTextF, CD.cd_ScrW);
  370.                     end else begin
  371.                         CD.cd_ScrH := 200;
  372.                         CD.cd_ScrW := 640;
  373.                     end;
  374.                     if FileVer >= V103 then begin
  375.                         ReadString(INTextF, CD.cd_RexxCmd1);
  376.                         ReadString(INTextF, CD.cd_RexxPort1);
  377.                         ReadString(INTextF, CD.cd_RexxCmd2);
  378.                         ReadString(INTextF, CD.cd_RexxPort2);
  379.                     end else begin
  380.                         CD.cd_RexxCmd1  := 'id SM_INITIAL';
  381.                         CD.cd_RexxPort1 := 'PLAY';
  382.                         CD.cd_RexxCmd2  := 'id SM_EXIT';
  383.                         CD.cd_RexxPort2 := 'PLAY';
  384.                     end;
  385.                     if FileVer >= V104 then begin
  386.                         ReadBool(INTextF, CD.cd_Wit);
  387.                         ReadBool(INTextF, CD.cd_Rexx);
  388.                     end else begin
  389.                         CD.cd_Wit := True;
  390.                         CD.cd_Rexx := True;
  391.                     end;
  392.                     if FileVer >= V107 then
  393.                         ReadBool(INTextF, CD.cd_NoClick)
  394.                     else
  395.                         CD.cd_NoClick := True;
  396.                     
  397.                     if FileVer >= V108 then
  398.                         ReadLong(INTextF, CD.cd_ScrT)
  399.                     else
  400.                         CD.cd_ScrT := 0;
  401.                                      
  402.                     if FileVer >= V109 then begin
  403.                         ReadBool(INTextF, CD.cd_WildStar);        
  404.                         ReadBool(INTextF, CD.cd_Shanghai);     
  405.                         ReadBool(INTextF, CD.cd_PopPubScr);    
  406.                     end else begin
  407.                         CD.cd_WildStar := False;
  408.                         CD.cd_Shanghai := True;
  409.                         CD.cd_PopPubScr := True;
  410.                     end;
  411.                                 
  412.                     If FileVer >= V10b then begin
  413.                         ReadString(INTextF, tmpStr);
  414.                         CD.cd_SFontName := tmpstr + #0;
  415.                         CD.cd_SFont.ta_Name := @CD.cd_SFontName[1];
  416.                         ReadLong(INTextF, ti);
  417.                         CD.cd_SFont.ta_YSize := ti;
  418.                         ReadLong(INTextF, ti);
  419.                         CD.cd_SFont.ta_Style := ti;
  420.                         ReadLong(INTextF, ti);
  421.                         CD.cd_SFont.ta_Flags := ti;
  422.                     end else begin
  423.                         CD.cd_SFontName := 'topaz.font'#0;
  424.                         CD.cd_SFont.ta_Name := @CD.cd_SFontName[1];
  425.                         CD.cd_SFont.ta_YSize := 8;
  426.                         CD.cd_SFont.ta_Style := FS_NORMAL;
  427.                         CD.cd_SFont.ta_Flags := FPF_ROMFONT;
  428.                     end;
  429.                     If FileVer >= V10c then
  430.                         ReadLong(INTextF, CD.cd_Quals)
  431.                     else
  432.                         CD.cd_Quals := 0;
  433.                                      
  434.                     If FileVer >= V10d then begin
  435.                         ReadLong(INTextF, CD.cd_Wait);
  436.                         if CD.cd_Wait < 0 then
  437.                             CD.cd_Wait := 0;
  438.                     end else
  439.                         CD.cd_Wait := 0;
  440.                                          
  441.                     CD.cd_Flush := True; 
  442.                     CD.cd_Test := False;
  443.                     If FileVer >= V10e then begin
  444.                         ReadString(INTextF, tmpStr);
  445.                         if TmpStr = 'FALSE' then
  446.                             CD.cd_Flush := False;
  447.                         ReadString(INTextF, tmpStr);
  448.                         if TmpStr = 'TRUE' then 
  449.                             CD.cd_Test := True;
  450.                     end;
  451.                         
  452.                     if FileVer >= V10f then begin
  453.                         ReadString(INTextF, CD.cd_RexxCmd3);
  454.                         ReadString(INTextF, CD.cd_RexxPort3);
  455.                     end else begin
  456.                         CD.cd_RexxCmd3  := 'id SM_PRECMD';
  457.                         CD.cd_RexxPort3 := 'PLAY';
  458.                     end;
  459.                     
  460.                     if FileVer >= V10h then
  461.                         ReadString(INTextF, CD.cd_DT)
  462.                     else
  463.                         CD.cd_DT := '';
  464.                     
  465.                     if FileVer >= V10i then
  466.                         ReadLong(INTextF, CD.cd_ScrDepth)
  467.                     else
  468.                         CD.cd_ScrDepth := 2;
  469.                         
  470.                     if FileVer >= V10j then begin
  471.                         ReadBool(INTextF, CD.cd_DTImmed);
  472.                         ReadBool(INTextF, CD.cd_DTRepeat);
  473.                     end else begin
  474.                         CD.cd_DTImmed := True;
  475.                         CD.cd_DTRepeat := True;
  476.                     end;
  477.                     
  478.                     if FileVer >= V10k then begin
  479.                         ReadLong(INTextF, CD.cd_App);
  480.                     end else begin
  481.                         CD.cd_App := APP_ALL;
  482.                     end;
  483.                     
  484.                     if FileVer >= V10l then begin
  485.                         ReadBool(INTextF, CD.cd_LogFile);
  486.                     end else begin
  487.                         CD.cd_LogFile := False;
  488.                     end;
  489.                     
  490.                     OK := AmigaDOS.Close_(INTextF);
  491.                     rc := True;
  492.                 end;
  493.             end else begin
  494.                 OK := AmigaDOS.Close_(INTextF);
  495.             End;
  496.         end else begin
  497.             OK := AmigaDOS.Close_(INTextF);
  498.         End;
  499.     end;
  500.     ReadConfigFile := rc;
  501. end;
  502.  
  503.  
  504.  
  505.